home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH4 / 4-3-4.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  4.4 KB  |  144 lines

  1. VERSION 5.00
  2. Begin VB.Form frm4_3_4 
  3.    Caption         =   "Bank Deposit"
  4.    ClientHeight    =   3210
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   3405
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   3210
  20.    ScaleWidth      =   3405
  21.    Begin VB.TextBox txtNumYrs 
  22.       Height          =   285
  23.       Left            =   2280
  24.       TabIndex        =   7
  25.       Top             =   1560
  26.       Width           =   975
  27.    End
  28.    Begin VB.PictureBox picBalance 
  29.       Height          =   255
  30.       Left            =   1680
  31.       ScaleHeight     =   195
  32.       ScaleWidth      =   1515
  33.       TabIndex        =   10
  34.       Top             =   2760
  35.       Width           =   1575
  36.    End
  37.    Begin VB.CommandButton cmdCompute 
  38.       Caption         =   "Compute Balance"
  39.       Height          =   495
  40.       Left            =   120
  41.       TabIndex        =   8
  42.       Top             =   2040
  43.       Width           =   3135
  44.    End
  45.    Begin VB.TextBox txtNumComp 
  46.       Height          =   285
  47.       Left            =   2280
  48.       TabIndex        =   5
  49.       Top             =   1080
  50.       Width           =   975
  51.    End
  52.    Begin VB.TextBox txtRate 
  53.       Height          =   285
  54.       Left            =   2280
  55.       TabIndex        =   3
  56.       Top             =   600
  57.       Width           =   975
  58.    End
  59.    Begin VB.TextBox txtAmount 
  60.       Height          =   285
  61.       Left            =   2280
  62.       TabIndex        =   1
  63.       Top             =   120
  64.       Width           =   975
  65.    End
  66.    Begin VB.Label lblBalance 
  67.       Caption         =   "Balance"
  68.       Height          =   255
  69.       Left            =   840
  70.       TabIndex        =   9
  71.       Top             =   2760
  72.       Width           =   735
  73.    End
  74.    Begin VB.Label lblNumYrs 
  75.       Caption         =   "Number of years"
  76.       Height          =   255
  77.       Left            =   720
  78.       TabIndex        =   6
  79.       Top             =   1560
  80.       Width           =   1455
  81.    End
  82.    Begin VB.Label lblNumComp 
  83.       Caption         =   "Number of times interest is compounded per year"
  84.       Height          =   495
  85.       Left            =   120
  86.       TabIndex        =   4
  87.       Top             =   1020
  88.       Width           =   2175
  89.    End
  90.    Begin VB.Label lblRate 
  91.       Caption         =   "Annual rate of interest"
  92.       Height          =   255
  93.       Left            =   240
  94.       TabIndex        =   2
  95.       Top             =   600
  96.       Width           =   1935
  97.    End
  98.    Begin VB.Label lblAmount 
  99.       Caption         =   "Amount of bank deposit"
  100.       Height          =   255
  101.       Left            =   120
  102.       TabIndex        =   0
  103.       Top             =   120
  104.       Width           =   2055
  105.    End
  106. Attribute VB_Name = "frm4_3_4"
  107. Attribute VB_GlobalNameSpace = False
  108. Attribute VB_Creatable = False
  109. Attribute VB_PredeclaredId = True
  110. Attribute VB_Exposed = False
  111. Private Sub cmdCompute_Click()
  112.   Dim p As Single, r As Single, c As Single, n As Single
  113.   'Find the future value of a bank deposit
  114.   Call InputData(p, r, c, n)
  115.   Call DisplayBalance(p, r, c, n)
  116. End Sub
  117. Private Sub DisplayBalance(p As Single, r As Single, c As Single, n As Single)
  118.   Dim balance As Single
  119.   'Display the balance in the picture box
  120.   picBalance.Cls
  121.   balance = FV(p, r, c, n)
  122.   picBalance.Print FormatCurrency(balance)
  123. End Sub
  124. Private Function FV(p As Single, r As Single, c As Single, n As Single) As Single
  125.   Dim i As Single, m As Single
  126.   'Find the future value of a bank savings account
  127.   'p  principal, the amount deposited
  128.   'r  annual rate of interest
  129.   'c  number of times interest is compounded per year
  130.   'n  number of years
  131.   'i  interest rate per period
  132.   'm  total number of times interest is compounded
  133.   i = r / c
  134.   m = c * n
  135.   FV = p * ((1 + i) ^ m)
  136. End Function
  137. Private Sub InputData(p As Single, r As Single, c As Single, n As Single)
  138.   'Get the four values from the text boxes
  139.   p = Val(txtAmount.Text)
  140.   r = Val(txtRate.Text)
  141.   c = Val(txtNumComp.Text)
  142.   n = Val(txtNumYrs.Text)
  143. End Sub
  144.